Contours of a 2D density estimate |
您所在的位置:网站首页 › filled of › Contours of a 2D density estimate |
Contours of a 2D density estimate
Source: R/geom-density2d.R, R/stat-density-2d.R
geom_density_2d.Rd
Perform a 2D kernel density estimation using MASS::kde2d() and display the results with contours. This can be useful for dealing with overplotting. This is a 2D version of geom_density(). geom_density_2d() draws contour lines, and geom_density_2d_filled() draws filled contour bands. Usage geom_density_2d( mapping = NULL, data = NULL, stat = "density_2d", position = "identity", ..., contour_var = "density", lineend = "butt", linejoin = "round", linemitre = 10, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_density_2d_filled( mapping = NULL, data = NULL, stat = "density_2d_filled", position = "identity", ..., contour_var = "density", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_density_2d( mapping = NULL, data = NULL, geom = "density_2d", position = "identity", ..., contour = TRUE, contour_var = "density", n = 100, h = NULL, adjust = c(1, 1), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_density_2d_filled( mapping = NULL, data = NULL, geom = "density_2d_filled", position = "identity", ..., contour = TRUE, contour_var = "density", n = 100, h = NULL, adjust = c(1, 1), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) Arguments mappingSet of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping. dataThe data to be displayed in this layer. There are three options: If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot(). A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created. A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)). positionPosition adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment. ...Arguments passed on to geom_contour binwidthThe width of the contour bins. Overridden by bins. binsNumber of contour bins. Overridden by breaks. breaksOne of: Numeric vector to set the contour breaks A function that takes the range of the data and binwidth as input and returns breaks as output. A function can be created from a formula (e.g. ~ fullseq(.x, .y)). Overrides binwidth and bins. By default, this is a vector of length ten with pretty() breaks. contour_varCharacter string identifying the variable to contour by. Can be one of "density", "ndensity", or "count". See the section on computed variables for details. lineendLine end style (round, butt, square). linejoinLine join style (round, mitre, bevel). linemitreLine mitre limit (number greater than 1). na.rmIf FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed. show.legendlogical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display. inherit.aesIf FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders(). geom, statUse to override the default connection between geom_density_2d() and stat_density_2d(). contourIf TRUE, contour the results of the 2d density estimation. nNumber of grid points in each direction. hBandwidth (vector of length two). If NULL, estimated using MASS::bandwidth.nrd(). adjustA multiplicative bandwidth adjustment to be used if 'h' is 'NULL'. This makes it possible to adjust the bandwidth while still using the a bandwidth estimator. For example, adjust = 1/2 means use half of the default bandwidth. Aestheticsgeom_density_2d() understands the following aesthetics (required aesthetics are in bold): x y alpha colour group linetype linewidth Learn more about setting these aesthetics in vignette("ggplot2-specs"). geom_density_2d_filled() understands the following aesthetics (required aesthetics are in bold): x y alpha colour fill group linetype linewidth subgroup Learn more about setting these aesthetics in vignette("ggplot2-specs"). Computed variablesThese are calculated by the 'stat' part of layers and can be accessed with delayed evaluation. stat_density_2d() and stat_density_2d_filled() compute different variables depending on whether contouring is turned on or off. With contouring off (contour = FALSE), both stats behave the same, and the following variables are provided: after_stat(density) The density estimate. after_stat(ndensity) Density estimate, scaled to a maximum of 1. after_stat(count) Density estimate * number of observations in group. after_stat(n) Number of observations in each group. With contouring on (contour = TRUE), either stat_contour() or stat_contour_filled() (for contour lines or contour bands, respectively) is run after the density estimate has been obtained, and the computed variables are determined by these stats. Contours are calculated for one of the three types of density estimates obtained before contouring, density, ndensity, and count. Which of those should be used is determined by the contour_var parameter. Dropped variables zAfter density estimation, the z values of individual data points are no longer available. If contouring is enabled, then similarly density, ndensity, and count are no longer available after the contouring pass. See alsogeom_contour(), geom_contour_filled() for information about how contours are drawn; geom_bin2d() for another way of dealing with overplotting. Examples m |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |